package com.chencs.app.shop.controller;

import com.alibaba.fastjson.JSON;
import com.chencs.app.AppCommon;
import com.chencs.app.shop.service.AppShopService;
import com.chencs.vo.biz.model.ModeModel;
import com.chencs.vo.biz.shop.NewShopModel;
import com.chencs.vo.biz.shop.ShopModel;
import com.chencs.vo.net.request.RequestBase;
import com.chencs.vo.net.request.ShopRequest;
import com.chencs.vo.net.response.AdverResponse;
import com.chencs.vo.net.response.NewShopResponse;
import com.chencs.vo.net.response.ShopInfoResponse;
import com.chencs.vo.net.response.ShopResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by fangzehua on 2017/8/15.
 */
@RestController
@RequestMapping("/app/shop")
public class AppShopController {

    @Autowired
    private AppShopService appShopService;

    /**
     *
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getShopList(@RequestBody ShopRequest request){
        ShopResponse response = new ShopResponse();
        List<ShopModel> list = appShopService.getShopList(request);
        try {
            if (list.isEmpty()){
                response.setCode(AppCommon.NULL);
                response.setMsg("店铺列表空");
            }else{
                response.setShops(list);
            }
        }catch (Exception e){
            response.setCode(AppCommon.ERROR);
            response.setMsg("获取店铺列表失败");
        }
        return  JSON.toJSONString(response);
    }


    @RequestMapping(value = "/getShopInfo", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getShopInfo(@RequestBody ShopRequest request){
        ShopInfoResponse response  = new ShopInfoResponse();

        try {
            response = appShopService.getShopInfo(request.getKey());
            if (response == null){
                response.setCode(AppCommon.NULL);
                response.setMsg("店铺空");
            }
        }catch (Exception e){
            response.setCode(AppCommon.ERROR);
            response.setMsg("获取店铺失败");
        }
        return  JSON.toJSONString(response);
    }





    @RequestMapping(value = "/getShopList", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getNewShopList(@RequestBody ShopRequest request){
        NewShopResponse response  = new NewShopResponse();
        try {
            List<NewShopModel> list = appShopService.getShopByCid(request);
            if (list.isEmpty()){
                response.setCode(AppCommon.NULL);
                response.setMsg("店铺空");
            }else{
                response.setShopModelList(list);
            }
        }catch (Exception e){
            response.setCode(AppCommon.ERROR);
            response.setMsg("获取店铺失败");
        }

        return  JSON.toJSONString(response);
    }











}
